MSDS 452

Assignment 2

Airlines flying among USA airports

Question 1:

Select randomly a list of 50 airports and plot the corresponding subgraph of airports-airlines.

Let $G$ be a graph on a set of nodes $V$ and let $X$ a subset of $V$. Then the networkx command to generate the subgraph of $A$ is $GA = G.subgraph(A)$ https://networkx.org/documentation/stable/reference/classes/generated/networkx.Graph.subgraph.html. For the random selection, you may use $A = random.sample(V, 50)$, where $V = G.nodes()$. Make sure that the (sub)graph $GA$ is not trivial.

Question 2:

Select 3 airports (either randomly or choose the ones that you have a preference for) and plot the corresponding subgraph of the egocentric networks which are centered at these airports.

If $n0$ is a node in a directed graph $G$, this is how to find the egocentric network centered at $n0$:

(1) First find in_n0 = list(G.predecessors(n0)) and out_n0 = list(G.successors(n0))

(2) Next find all neighbors_n0 = list(set(list(G.predecessors(n0)) + list(G.successors(n0))+[n0]))

(3) Finally get G.subgraph(neighbors_n0)

Do the above for each one of the 3 egos and finally get G.subgraph(list(set(neighbors_n0+neighbors_n1+neghbors_n2)))

Question 3:

Select a list of 10 airlines (either randomly or choose the ones that you have a preference for) together with the airports to which these airlines fly. Take the corresponding subgraph in the bipartite graph of airlines vs. airports and plot it.

the problem with the original version of the above cell was that the variable b was set in the first cell of question 2:

for b in set(list(G.predecessors(a)) + list(G.successors(a))+[a]):

which only retained the final value of iterating through. (for me it was Kahului airport)

Gc reduces to only the most connected subgraph